﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Eassets.Service.Global;
using Eassets.Service;
using Eassets.Layered.Domain;
using Eassets.Service.Secure;

namespace Eassets.UI
{
    public partial class Main : System.Web.UI.MasterPage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (Session["LoggedUserId"] != null && Convert.ToInt16(Session["LoggedUserId"]) > 0)
            {
                OrganizationLevelListService organizationLevelListService=new OrganizationLevelListService();
               // string companyCode=Convert.ToString(Session["LogginCompany"]);
                dropDownListCompany.DataSource = organizationLevelListService.GetAllOrganizationLevelList().Where(x => x.OrganizationLevelMode == "C").ToList();
                dropDownListCompany.DataTextField = "Code";
                dropDownListCompany.DataValueField = "OrganizationLevelListId";
                dropDownListCompany.DataBind();

                EmployeeService emopyeeService = new EmployeeService();
                Employee employee = new Employee();
               employee= emopyeeService.GetByIdEmployee(Convert.ToInt64(Session["LoggedUserId"]));
               linkProfile.Text = employee.EmployeeName;

                //Get Security User Group
               SecurityGroupUserService securityUserGroupService = new SecurityGroupUserService();
               long SecurityGroupId = securityUserGroupService.GetSecurityGroupIdByUserId(Convert.ToInt64(Session["LoggedUserId"]));
               Session["SecurityGroupId"] = SecurityGroupId;
            }
            else {
                Response.Redirect("~/Default.aspx");
            }
        }

        protected void dropDownListCompany_SelectedIndexChanged(object sender,EventArgs e) 
        {
        
        }

        protected void linkLogOut_Click(object sender, EventArgs e) 
        {
            //UserService userService = new UserService();
            //userService.ExpireLogin(Convert.ToInt64(Session[Global.KeyLoginId]));
            Session.Clear();
            Session["LoggedUserId"] = null;
            Response.Redirect("~/Default.aspx");
        }
        
    }
}